package com.li.server.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.li.client.entities.BookType;
import com.li.server.jdbc.JDBCExecutor;
import com.li.server.jdbc.JDBCUtil;

public class BookTypeDaoImpl implements BookTypeDao {

	@Override
	public List<BookType> getAllBookType() {
		return new JDBCUtil().executeSQL(new JDBCExecutor<List<BookType>>() {

			@Override
			public List<BookType> execute(Connection conn) throws Exception {
				PreparedStatement ps = conn.prepareStatement("select PK_BOOK_TYPE_ID, TYPE_NAME from BOOK_TYPE");
				
				ResultSet rs = ps.executeQuery();
				List<BookType> btList = new ArrayList<BookType>();
				BookType bt = null;
				while(rs.next()) {
					bt = new BookType();
					
					bt.setPkBookTypeiD(rs.getInt("PK_BOOK_TYPE_ID"));
					bt.setTypeName(rs.getString("TYPE_NAME"));
					
					btList.add(bt);
				}
				
				return btList;
			}
		});
	}

}
